package _17_剑指Offer;

public class _43_剑指Offer1n整数中1出现的次数 {

    // 对于计算
    public int countDigitOne(int n) {
        long mulk = 1;
        int res = 0;
        while (n >= mulk) {
            res += n / (10 * mulk) * mulk + Math.min(Math.max(n % (10 * mulk) - mulk + 1, 0), mulk);
            mulk *= 10;
        }
        return res;
    }

}
